﻿<%@ WebHandler Language="C#" Class="SYS_Message_add" %>

using System;
using System.Web;
using System.Web.Script.Serialization;
using System.Web.SessionState;

public class SYS_Message_add : IHttpHandler, IRequiresSessionState
{
    sqlhelp sql = new sqlhelp();
    result result = new result();
    string str = "";
    
    public void ProcessRequest (HttpContext context) {
        try
        {
            if (context.Session["comid"] == null)
            {
                result.code = "-1";
                result.msg = "用户未登录";
                unit.send(context, result);
                return;
            }

            string Id = Guid.NewGuid().ToString();
            string StoreId = context.Session["comid"].ToString();
            //string StoreId = "9f1dfd1d-7bf3-479e-8c35-01a59d1ab167";
            string UserId = "00000000-0000-0000-0000-000000000000";
            string UserName = "";

            string SubStance = "";//内容
            string Title = "";//标题
            string Url = "";//url
            string ImageUrl = "";//图标
            int AuditFlg = 0;
            
            string CreateTime = DateTime.Now.ToString();
            string Enable = "1";

            if (context.Request["SubStance"] == null)
            {
                result.code = "0";
                result.msg = "未传递内容参数";
                unit.send(context, result);
                return;
            }
            else
            {
                SubStance = context.Request["SubStance"].ToString();
            }
            if (context.Request["Title"] == null)
            {
                result.code = "0";
                result.msg = "未传递标题参数";
                unit.send(context, result);
                return;
            }
            else
            {
                Title = context.Request["Title"].ToString();
            }
            if (context.Request["Url"] == null)
            {
                result.code = "0";
                result.msg = "未传递Url参数";
                unit.send(context, result);
                return;
            }
            else
            {
                Url = context.Request["Url"].ToString();
            }
            if (context.Request["ImageUrl"] == null)
            {
                result.code = "0";
                result.msg = "未传递图标参数";
                unit.send(context, result);
                return;
            }
            else
            {
                ImageUrl = context.Request["ImageUrl"].ToString();
            }

            string ImageUrlID = Guid.NewGuid().ToString();

            str = "insert into SYS_Message(Id,StoreId,UserId,UserName,SubStance,Title,Url,ImageUrl,AuditFlg,CreateTime,Enable) values('" + Id + "','" + StoreId + "','" + UserId + "','" + UserName + "','" + SubStance + "','" + Title + "','" + Url + "','" + ImageUrlID + "','" + AuditFlg + "','" + CreateTime + "'," + Enable + ")";
            if (sql.ExecuteNonQuery(str) > 0)
            {
                str = "insert into SYS_Image(Id,Linkid,Path,CreateTime,Enable) values('" + Guid.NewGuid().ToString() + "','" + ImageUrlID + "','" + ImageUrl + "','" + DateTime.Now.ToString() + "',1)";
                sql.ExecuteNonQuery(str);
                
                result.code = "1";
                result.msg = "";
            }
            else
            {
                result.code = "0";
                result.msg = "添加失败";
            }

        }
        catch (Exception e1)
        {
            result.code = "0";
            result.msg = e1.Message;
        }


        unit.send(context, result);
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}